package com.xm.xmwa1706090.service.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.xm.xm.dto.ResultDto;
import com.xm.xm.dto.SearchDto;
import com.xm.xm.util.ErrorCode;
import com.xm.xmwa1706090.service.mapper.QbExplainMapper;
import com.xm.xmwa1706090.service.model.QbExplain;
import com.xm.xmwa1706090.service.service.QbExplainService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;

/**
 * 杭州新苗网络科技有限公司
 * @author meihf
 * @date 2017/07/10
 * @description
*/ 
@Service("qbExplainService")
public class QbExplainServiceImpl extends ServiceImpl<QbExplainMapper,QbExplain> implements QbExplainService {

    @Autowired
    QbExplainMapper qbExplainMapper;

    @Override
    public ResultDto news(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        JSONObject field = new JSONObject();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
            int type = field.getInt("type");
            List<QbExplain> qbExplainList = qbExplainMapper.selectList(new EntityWrapper<QbExplain>().where(" type={0} ",type));
            if (qbExplainList.size()==0){
                resultDto.setCode(ErrorCode.C11001);
                resultDto.setMsg(ErrorCode.E11001);
                return resultDto;
            }else {
                resultDto.setData(qbExplainList.get(0));
            }
        }catch (RuntimeException e ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }

}

